<?php
namespace Home\Controller;
use Think\Controller;
class PersonnelController extends BackController {
	public function AddWorkers(){
		$staff = D('Personnel');
		if(IS_POST){
			$id = I('post.id','','int');
			//var_dump($id);exit;
			if(empty($id)){
				if($staff->create()) {
						if($staff->add($_POST)) {
								$this->success('新增成功',U('Personnel/WorkersList'));
						}else {
								$this->error('新增失败',U('Personnel/WorkersList'));
						}
				}else{
					$this->error($staff->getError());
				}
			}else{
				if($staff->create()) {
						if($staff->where('id='.$id)->save($_POST) !== false) {
								$this->success('编辑成功',U('Personnel/WorkersList'));
						}else {
								$this->error('编辑失败',U('Personnel/WorkersList'));
						}
				}else {
						$this->error($staff->getError());
				}
			}
		}else{
			$id = I('get.id','','int');
			if($id != ''){
				$staff_data = $staff->where('id='.$id)->find();
				$this->assign('staff_data',$staff_data);	
			}
			$other = $this->all_other();
			$this->assign('other',$other);
			
			$bm_name = M('power')->field('id,title')->select();
			$this->assign('bm_name',$bm_name);
			//var_dump($bm_name);
			$this->display();
		}
	}

	public function Worktime(){
		$this->display();
	}

	public function WorkersList(){
		$staff = D('Personnel');
		if(IS_POST){
			
		}else{
			$where['xid'] = array('eq',session('qe_user')['xid']);
			$count      = $staff->where($where)->count();// 查询满足要求的总记录数
			$Page       = new \Think\Page($count,$this->all_count(1));// 实例化分页类 传入总记录数和每页显示的记录数(25)
			$show       = $Page->show();// 分页显示输出// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
			$staff_list = $staff->where($where)->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
			
			foreach ($staff_list as $k=>$v){
				$staff_list[$k]['xname'] = $this->basname($v['xid']);
			}
			$this->assign('staff_list',$staff_list);
			$this->assign('page',$show);
			$other = $this->all_other();
			$this->assign('other',$other);
			
			
			$bm_name = M('power')->field('id,title')->select();
			$this->assign('bm_name',$bm_name);
			//var_dump($staff_list);
			$this->display();	
		}
	}
}